// 给一串单元格信息, 输出最终单元格内容
// 这道题, 感觉有点变态, 因为输入的处理, 就很耗时, 各种问题都可能
// 然后是dfs
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let initArr = [];
rl.on("line", (line)=>{
    if(initArr.length === 0) {
        initArr = line.split(/\s*,\s*/)
        console.log(getResult(initArr))
        // clear
        initArr.length = 0
    }

})
function getResult(initArr) {
    if(!valid(initArr)){
        return "-1"
    }

    // 过程中需要验证循环引用
    // dfs
    let map = {}
    let code = "A".charCodeAt(0)
    for (let i = 0; i < initArr.length; i++) {
        let char = String.fromCharCode(code + i)
        map[char] = initArr[i]
    }
    let reg = /<([A-Z])>/g
    for (const key of Object.keys(map)) {
        let str = map[key]
        let match = str.match(reg)
        if(match) {
            let char = match[0].replace("<", "").replace(">", "")
            let visited = new Array(initArr.length).fill(false)
            let result = dfs(map, char, visited, code)
            if(result === "#") {
                return "-1"
            }
            map[key] = map[key].replace(match[0], result)
            if(map[key].length > 100) {
                return "-1"
            }
        }
    }
    return Object.values(map).join(",")
}

function valid(initArr) {
    // 26个单元格
    if(initArr.length > 26) return false

    //内容中是否包含空串, 或超过100字符
    let code = "A".charCodeAt(0)
    let reg1 = /[^<>A-Za-z0-9]/
    let reg2 = /</g
    let reg3 = />/g
    let reg4 = /<([A-Z]*)>/g
    for (let i = 0; i < 26 ; i++) {
        let str = initArr[i]
        if(str === "" || str.length > 100) {
            return false
        }
        //每个单元格只包含字母和数字以及<> 分割单元引用
        if(reg1.test(str)) return false

        // 不存在多重<>, 验证<>中内容是否合法
        let match2 = str.match(reg2);
        let match3 = str.match(reg3);
        let match4 = str.match(reg4);
        if(match2 && match2.length > 1) {
            return false
        }
        if(match3 && match3.length > 1) {
            return false
        }
        if(match4) {
            let match = match4[0].replace("<", "").replace(">", "")
            //不存在多重<>, 验证<>中内容是否合法
            if(match.length !== 1) return false
            //对应编号A-Z
            if(!/[A-Z]/.test(match)) return false

            // 自己调自己
            if(match === String.fromCharCode(code + i)) {
                return false
            }
        } else {
            return true
        }
    }
    return true
}

function dfs(map, char, visited, code){
    let diff = char.charCodeAt(0) - code
    // 循环引用
    if(visited[diff]) {
        return "#"
    }
    visited[diff] = true

    let reg = /<([A-Z])>/g
    let match = map[char].match(reg)
    if(match) {
        let str = match[0].replace("<", "").replace(">", "")
        let result = dfs(map, str, visited, code)
        if(result === "#") {
            return "#"
        }
        map[str] = result

        return map[char].replace(match[0], result)

    } else {
        return map[char]
    }
}